//
//  RedController.m
//  ProjectDemo
//
//  Created by IOS3 on 2018/11/21.
//  Copyright © 2018 IOS3. All rights reserved.
//

#import "RedController.h"

@interface RedController ()


@property (nonatomic, strong) UIView *sheetAlert;
@property (nonatomic, assign) BOOL flag;

@end

@implementation RedController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    self.flag = true;
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    [self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:@"Cell"];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    
    self.sheetAlert = [[UIView alloc] init];
    self.sheetAlert.backgroundColor = UIColor.blueColor;
    [self.view addSubview:self.sheetAlert];
    
    [self.sheetAlert mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(44);
        make.left.right.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view.mas_bottom);
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.textLabel.text = [NSString stringWithFormat:@"%ld - %ld", indexPath.section, indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.flag) {
        [UIView animateWithDuration:0.25 animations:^{
            [self.sheetAlert mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(44);
                make.left.right.mas_equalTo(self.view);
                make.bottom.mas_equalTo(self.view);
            }];
        }];
    }
    else {
        [UIView animateWithDuration:0.25 animations:^{
            [self.sheetAlert mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(44);
                make.left.right.mas_equalTo(self.view);
                make.top.mas_equalTo(self.view.mas_bottom);
            }];
        }];
    }
    self.flag = !self.flag;
}
@end
